﻿<UserControl
    x:Class="Notepads.Controls.TextEditor.TextEditor"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:controls="using:Notepads.Controls"
    xmlns:textEditor="using:Notepads.Controls.TextEditor"
    xmlns:diffViewer="using:Notepads.Controls.DiffViewer"
    xmlns:findAndReplace="using:Notepads.Controls.FindAndReplace"
    xmlns:goTo="using:Notepads.Controls.GoTo"
    mc:Ignorable="d"
    Background="{ThemeResource SystemControlForegroundTransparentBrush}">

    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.ThemeDictionaries>
                <ResourceDictionary x:Key="Light">
                    <SolidColorBrush x:Key="SplitViewBackgroundThemeBrush"
                                     Opacity="0.4"
                                     Color="White"/>
                    <SolidColorBrush x:Key="GridSplitterBackgroundThemeBrush"
                                     Opacity="0.5"
                                     Color="LightGray"/>
                </ResourceDictionary>
                <ResourceDictionary x:Key="Dark">
                    <SolidColorBrush x:Key="SplitViewBackgroundThemeBrush"
                                  Opacity="0.25"
                                  Color="Black"/>
                    <SolidColorBrush x:Key="GridSplitterBackgroundThemeBrush"
                                     Opacity="0.3"
                                     Color="Black"/>
                </ResourceDictionary>
                <ResourceDictionary x:Key="HighContrast">
                    <SolidColorBrush x:Key="SplitViewBackgroundThemeBrush"
                                     Color="{ThemeResource SystemColorHighlightColor}"/>
                    <SolidColorBrush x:Key="GridSplitterBackgroundThemeBrush"
                                     Color="{ThemeResource SystemColorHighlightColor}"/>
                </ResourceDictionary>
            </ResourceDictionary.ThemeDictionaries>

            <Style x:Key="CustomGridSplitterStyle" TargetType="controls:GridSplitter">
                <Setter Property="IsTabStop" Value="True"/>
                <Setter Property="UseSystemFocusVisuals" Value="True"/>
                <Setter Property="HorizontalAlignment" Value="Stretch"/>
                <Setter Property="VerticalAlignment" Value="Stretch"/>
                <Setter Property="IsFocusEngagementEnabled" Value="True"/>
                <Setter Property="MinWidth" Value="2"/>
                <Setter Property="MinHeight" Value="2"/>
                <Setter Property="Background" Value="Transparent"/>
                <Setter Property="GripperForeground" Value="Transparent"/>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="controls:GridSplitter">
                            <Grid x:Name="RootGrid" Background="Transparent">
                                <VisualStateManager.VisualStateGroups>
                                    <VisualStateGroup x:Name="GridSplitterStates">
                                        <VisualState x:Name="Normal"/>
                                        <VisualState x:Name="PointerOver">
                                            <VisualState.Setters>
                                                <Setter Target="RootGrid.Background" Value="{ThemeResource GridSplitterBackgroundThemeBrush}"/>
                                            </VisualState.Setters>
                                        </VisualState>
                                        <VisualState x:Name="Pressed">
                                            <VisualState.Setters>
                                                <Setter Target="RootGrid.Background" Value="{ThemeResource GridSplitterBackgroundThemeBrush}"/>
                                            </VisualState.Setters>
                                        </VisualState>
                                    </VisualStateGroup>
                                </VisualStateManager.VisualStateGroups>
                                <ContentPresenter Content="{TemplateBinding Element}" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch"/>
                            </Grid>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </ResourceDictionary>
    </UserControl.Resources>
    
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition x:Name="EditorRowDefinition" Height="*"/>
            <RowDefinition x:Name="SideBySideDiffViewRowDefinition" Height="0"/>
        </Grid.RowDefinitions>

        <Grid Row="0">
            <Grid.ColumnDefinitions>
                <ColumnDefinition x:Name="EditorColumnDefinition" Width="*" MinWidth="100"/>
                <ColumnDefinition x:Name="SplitPanelColumnDefinition" Width="0"/>
            </Grid.ColumnDefinitions>
            <Grid>
                <textEditor:TextEditorCore x:Name="TextEditorCore" 
                                           Style="{StaticResource TextEditorCore}" 
                                           Grid.Column="0"
                                           Padding="6 , 6, 10, 6"/>
                <controls:InAppNotification x:Name="FindAndReplacePlaceholder"
                                            x:Load="false"
                                            Padding="0"
                                            Margin="0"
                                            HorizontalAlignment="Right"
                                            VerticalAlignment="Top"
                                            Style="{StaticResource FindAndReplacePlaceholder}"
                                            ShowDismissButton="True"
                                            AnimationDuration="0:0:0.050"
                                            VerticalOffset="10"
                                            HorizontalOffset="-22"
                                            FontWeight="Light"
                                            BorderThickness="1"
                                            Closed="FindAndReplacePlaceholder_Closed">
                    <controls:InAppNotification.Content>
                        <findAndReplace:FindAndReplaceControl x:Name="FindAndReplaceControl" 
                                                              Width="340"
                                                              OnDismissKeyDown="FindAndReplaceControl_OnDismissKeyDown"
                                                              OnToggleReplaceModeButtonClicked="FindAndReplaceControl_OnToggleReplaceModeButtonClicked"
                                                              OnFindReplaceControlKeyDown="TextEditorCore_OnKeyDown"
                                                              OnFindAndReplaceButtonClicked="FindAndReplaceControl_OnFindAndReplaceButtonClicked"/>
                    </controls:InAppNotification.Content>
                </controls:InAppNotification>
                <controls:InAppNotification x:Name="GoToPlaceholder"
                                            x:Load="false"
                                            Padding="0"
                                            Margin="0"
                                            HorizontalAlignment="Right"
                                            VerticalAlignment="Top"
                                            Style="{StaticResource FindAndReplacePlaceholder}"
                                            ShowDismissButton="True"
                                            AnimationDuration="0:0:0.050"
                                            VerticalOffset="0"
                                            HorizontalOffset="-22"
                                            FontWeight="Light"
                                            BorderThickness="1"
                                            Closed="GoToPlaceholder_Closed">
                    <controls:InAppNotification.Content>
                        <goTo:GoToControl x:Name="GoToControl"
                                          Width="260"
                                          OnDismissKeyDown="GoToControl_OnDismissKeyDown"
                                          OnGoToControlKeyDown="TextEditorCore_OnKeyDown"
                                          OnGoToButtonClicked="GoToControl_OnGoToButtonClicked"/>
                    </controls:InAppNotification.Content>
                </controls:InAppNotification>
            </Grid>
            <controls:DropShadowPanel    
                Canvas.ZIndex="50"
                Grid.Column="1"
                ShadowOpacity="0.3"
                BlurRadius="12"
                VerticalAlignment="Stretch"
                HorizontalAlignment="Left">
                <Grid Width="2"/>
                <controls:DropShadowPanel.Clip>
                    <RectangleGeometry Rect="-12,0,12,12960"></RectangleGeometry>
                </controls:DropShadowPanel.Clip>
            </controls:DropShadowPanel>
            <ContentPresenter x:Name="SplitPanel" 
                              x:Load="False"
                              Canvas.ZIndex="100"
                              Padding="10,0,0,0"
                              Background="{ThemeResource SplitViewBackgroundThemeBrush}"
                              AutomationProperties.AccessibilityView="Raw"
                              Grid.Column="1"/>
            <controls:GridSplitter x:Name="GridSplitter"
                                   x:Load="False"
                                   Canvas.ZIndex="150"
                                   Style="{StaticResource CustomGridSplitterStyle}"
                                   MinWidth="10"
                                   GripperCursor="Default"
                                   HorizontalAlignment="Left"
                                   Grid.Column="1"
                                   ResizeDirection="Auto"
                                   ResizeBehavior="BasedOnAlignment"
                                   CursorBehavior="ChangeOnSplitterHover"
                                   Width="10">
                <controls:GridSplitter.RenderTransform>
                    <TranslateTransform X="0" />
                </controls:GridSplitter.RenderTransform>
            </controls:GridSplitter>
        </Grid>
        <diffViewer:SideBySideDiffViewer x:Name="SideBySideDiffViewer"
                                         x:Load="False"
                                         Grid.Row="1"/>
    </Grid>
</UserControl>
